package model.eval;

import enums.TestPanelEnum;
import j_util.Utiles;
import model.TruthTable;
/*

    This file is part of Logica-Logike.

    Logica-Logike is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation version 3 of the License.

    Logica-Logike is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with Logica-Logike.  If not, see <http://www.gnu.org/licenses/>.

 */
/**
 * Ejercicio de tablas de verdad;
 *
 * @author Jose Martin Rozanec;
 */
public class TestTruthTable extends TestExcercise {
    /**
     * Constructor;
     */
    public TestTruthTable() {
        this.panelEnum = TestPanelEnum.TRUTH_TABLE;
    }

    public int getAchievedScore() {
        String[][] tableSolution = ((TruthTable) getExcerciseData()).getResult();
        String[][] studentsSolution = (String[][]) getStudentsSolution();
        for (int j = 0; j < tableSolution.length; j++) {
            for (int i = 0; i < tableSolution[0].length; i++) {
                if (!Utiles.removeSpacesFromString(tableSolution[j][i]).
                        equalsIgnoreCase(Utiles.removeSpacesFromString(studentsSolution[j][i]))) {
                    return getIncorrectScore();
                }
            }
        }
        return getCorrectScore();
    }

    public String toString() {
        return (((TruthTable) getExcerciseData()).toString()) + "\n" +
                displayResult(((TruthTable) getExcerciseData()).getResult());
    }

    public String getStudentSolutionString() {
        System.out.println("" + getExcerciseData());
        System.out.println("" + (getStudentsSolution()));
        return (((TruthTable) getExcerciseData()).toString()) + "\n" +
                displayResult((String[][]) getStudentsSolution());
    }

    private String displayResult(String[][] result) {
        String[][] resultMatrix = result;
        StringBuffer buffer = new StringBuffer();
        for (int j = 0; j < resultMatrix.length; j++) {
            for (int i = 0; i < resultMatrix[0].length; i++) {
                System.out.println("" + result[j][i]);
                if (resultMatrix[j][i] == null) {
                    buffer.append("   [ ]     ");
                } else {
                    buffer.append("   [" + resultMatrix[j][i] + "]     ");
                }
            }
            buffer.append("\n");
        }
        return buffer.toString();
    }
}
